package demo1;

/**
 * @Author 12629
 * @Date 2022/4/6 19:15
 * @Description：
 */
class Shape {
    public void draw() {
        System.out.println("画图形！");
    }
}

class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("●");
    }
}

class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("♦");
    }
}

class Triangle extends Shape{
    @Override
    public void draw() {
        System.out.println("△");
    }
}

class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("❀");
    }
}



public class TestDemo {

    /**
     * "cycle", "rect", "cycle", "rect", "flower"
     */
    public static void drawShapes1() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String shape : shapes) {
            if (shape.equals("cycle")) {
                cycle.draw();
            } else if (shape.equals("rect")) {
                rect.draw();
            } else if (shape.equals("flower")) {
                flower.draw();
            }
        }
    }

    public static void drawShapes() {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        Shape[] shapes = {cycle,rect,cycle,rect,flower};
        for (Shape shape : shapes) {
            shape.draw();
        }//一下子 代码 就高大上了
       /* Shape[] shapes = new Shape[5];
        shapes[0] = new Cycle();
        shapes[1] = new Rect();*/
    }

    public static void drawMap(Shape shape) {
        shape.draw();
    }

    public static void main(String[] args) {
        drawShapes();
    }

    public static void main2(String[] args) {
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Triangle triangle = new Triangle();
        drawMap(cycle);
        drawMap(rect);
        drawMap(triangle);
        drawMap(new Flower());
    }

    public static void main1(String[] args) {
        Shape shape = new Cycle();
        shape.draw();
    }
}
